package design.patterns.creational.singleton.lazy.v1;

/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2019/4/1 10:32
 */

import design.patterns.creational.singleton.MyThread;

import java.util.concurrent.CountDownLatch;

/**
 * 懒汉式 线程不安全单例示例
 */
public class LazySingleton {
    private static LazySingleton lazySingleton = null;

    private LazySingleton(){

    }

    public static LazySingleton getInstance(){
        if(lazySingleton == null){
            lazySingleton = new LazySingleton();
        }
        return lazySingleton;
    }
}


class Test {
    public static void main(String[] args) {
        //单线程安全
       /* LazySingleton instance = LazySingleton.getInstance();
        System.out.println(instance);

        LazySingleton instance2 = LazySingleton.getInstance();
        System.out.println(instance2);*/
        //多线程不安全
        int count = 800;
        for (int i = 0; i < count; i++) {
            MyThread t1 = new MyThread();
            t1.start();

        }
        System.out.println("main....");

    }
}
